
package transientTest.clone;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


/**
 * 比较两种赋值的区别
 * 
 * @author lcx
 *
 */
public class Compare2CopyTest implements java.io.Serializable,Cloneable
{
	private String name="liu";
	private int age=40;
	private Person person=new Person();

	public static void main(String[] args) throws Exception
	{
		Compare2CopyTest copy=new Compare2CopyTest();
		copy.name="abc";
		copy.person.name="gang";
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		ObjectOutputStream oos=new ObjectOutputStream(bos);
		oos.writeObject(copy);
		ByteArrayInputStream bai=new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream ois=new ObjectInputStream(bai);
		Compare2CopyTest dcopy=(Compare2CopyTest)ois.readObject();
		copy.name="def";
		System.out.println("dcopy:"+dcopy.name+"  "+dcopy.person.name);
		Compare2CopyTest copy1=(Compare2CopyTest) copy.clone();
		copy1.person.name="HEHE";
		copy1.age=100;
		System.out.println("copy1:"+copy1.age+"  "+copy1.person.name);

		System.out.println("copy:"+copy.age+"  "+copy.person.name);
	}
}

class Person implements java.io.Serializable
{
	public String name="LIAO";
	public int age=30;
}
